#pragma once
#include "..\cpptooltip\PPTooltip.h"
#include "ColorListCtrl.h"

namespace UIExtended
{
	// CWorkspaceBar2

	class CWorkspaceBar2 : public CDockablePane
	{
		DECLARE_DYNAMIC(CWorkspaceBar2)
	protected:
		CWorkspaceBar2( CWnd* pParent );
	public:
		virtual ~CWorkspaceBar2();

	protected:
		virtual CWnd& GetChild()=0;
		afx_msg void OnSize(UINT nType, int cx, int cy);
		CWnd*m_Parent;

	protected:
		DECLARE_MESSAGE_MAP()
	public:
		afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	};


	template<class T>
	class CWorkspaceBar : public CWorkspaceBar2
	{
	public:
		CWorkspaceBar( CWnd* pParent ) : CWorkspaceBar2( pParent ) {}
		virtual ~CWorkspaceBar(){}
		T m_wndChild;
	protected:
		virtual CWnd& GetChild() { return m_wndChild; }
		virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
		{
			return CWorkspaceBar2::OnNotify(wParam, lParam, pResult);
		}
	};

	template<> 
	class CWorkspaceBar<CColorListCtrl> : public CWorkspaceBar2
	{
	public:
		CWorkspaceBar( CWnd* pParent ) : CWorkspaceBar2( pParent ) {}
		virtual ~CWorkspaceBar(){}
		CColorListCtrl m_wndChild;
	protected:
		virtual CWnd& GetChild() { return m_wndChild; }
		virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
		{
			NMHDR*nm=(NMHDR*)lParam;
			if ( NM_RCLICK==nm->code && wParam!=0 )
			{
				NMLISTVIEW* pNMListView = (NMLISTVIEW*)lParam;
				if ( pNMListView->iItem!=-1 )
				{
					int SelectIndex;
					m_wndChild.m_CurSel = SelectIndex = pNMListView->iItem;

					CMenu menu;
					RECT rc;

					VERIFY(menu.LoadMenu (wParam));

					CMFCPopupMenu* pPopupMenu = new CMFCPopupMenu;
					pPopupMenu->SetAutoDestroy (TRUE);

					m_wndChild.GetWindowRect(&rc);
					pPopupMenu->Create (this, pNMListView->ptAction.x + rc.left, pNMListView->ptAction.y + rc.top, menu.GetSafeHmenu ());
					*pResult = 0;
					return TRUE;
				}
			}
			return CWorkspaceBar2::OnNotify(wParam, lParam, pResult);
		}
	};

}